package com.zzuli.yxy.task.springDataPipeline;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zzuli.yxy.entity.Album;
import com.zzuli.yxy.mapper.AlbumMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * 会获取一种数据
 * album：专辑id 专辑图片 发行时间 发行公司 备注 存入数据库
 * @auther pony
 * @create 2023-04-05 16:24
 */
@Component
public class AlbumPipeline implements Pipeline {
    @Autowired
    private AlbumMapper albumMapper;

    @Override
    public void process(ResultItems resultItems, Task task) {
        //1、获取 album，存入数据库
        Album albumTask = resultItems.get("album");
        System.out.println("最终存入数据库的信息 albumTask:"+albumTask);
        //2、存到数据库
        LambdaUpdateWrapper<Album> uw = new LambdaUpdateWrapper<>();
        uw.eq(Album::getAlbumId, albumTask.getAlbumId());
        uw.set(Album::getAlbumImg, albumTask.getAlbumImg());
        uw.set(Album::getAlbumRemarks, albumTask.getAlbumRemarks());
        uw.set(Album::getAlbumCompany, albumTask.getAlbumCompany());
        uw.set(Album::getAlbumReleaseTime, albumTask.getAlbumReleaseTime());
        albumMapper.update(albumTask,uw);
    }
}
